﻿using FineUI;
using System;
using ZHDJ.Core.Util;
using ZHDJ.Data.BLL;
using ZHDJ.Data.Models.Org;
using ZHDJ.PersonalCenter.BLL;

namespace ZHDJ.PersonalCenter.Module.SMS
{
    public partial class SMSSendEdit : PageBase
    {
        #region ViewPower

        /// <summary>
        /// 本页面的浏览权限，空字符串表示本页面不受权限控制
        /// </summary>
        public override string ViewPower
        {
            get
            {
                return "";
            }
        }
        #endregion

        #region Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        private void LoadData()
        {
            btnClose.OnClientClick = ActiveWindow.GetHideReference();
        }
        #endregion

        #region Events

        private void SaveData()
        {
            if(!string.IsNullOrEmpty(this.ppMember.Value))
            {
                PartyOrgMember orgMember = null;

                foreach(string member in this.ppMember.Value.Split(','))
                {
                    orgMember = DB.PartyOrgMembers.Find(member);
                    SMSHelper.CreateSmsSendRecord(orgMember.MobileNo, FilterSpecialCharacters.Filter(txtSmsContent.Text.Trim()));
                }
            }
        }

        /// <summary>
        /// 保存并关闭按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSaveClose_Click(object sender, EventArgs e)
        {
            SaveData();

            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
        }
        #endregion
    }
}